﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_Modes;
using Zor_Tools;
using Zor_IDAL;

namespace Zor_DAL
{
    public class Users_DAL
    {
        public static List<Users> GetUserList()
        {
            var sql = "select * from Users";
            List<Users> lst = DapperQuery<Users>.DoQueryList(sql, null);
            return lst;
        }

        public static Users GetUsersById(int id)
        {
            var sql = "select * from Users where User_Id=@User_Id";
            return DapperQuery<Users>.DoQueryT(sql, new { User_Id = id });
        }

        public static BaseAnswer InserUsers(Users us)
        {
            var sql = "insert into Users values(@User_UserName,@User_Password,@User_RealName,@User_CreateDate,@User_CreateName,@User_DtParentId,@User_DtParentName)";
            BaseAnswer bar = DapperInsert<Users>.DoInsert(sql, us);
            return bar;
        }

        public static BaseAnswer UpdateUses(Users us)
        {
            var sq1 = "update Users set User_UserName=@User_UserName,User_Password=@User_Password,User_RealName=@User_RealName,User_DtParentId=@User_DtParentId,User_DtParentName=@User_DtParentName where User_Id=@User_Id";
            BaseAnswer bar = DapperEdit<Users>.DoEdit(sq1, us);
            return bar;
        }

        public static BaseAnswer DelteUsers(int[] ids)
        {
            var sql = "delete from Users where User_Id in @User_Id";
            BaseAnswer bar = DapperDelete<Users>.DoDelete(sql, new { User_Id = ids });
            return bar;
        }

        public static Users GetUserByNameAndPass(Users us)
        {
            var sql = "select User_Id,User_UserName,User_Password,User_RealName,User_DtParentId,User_DtParentName from Users where User_UserName=@User_UserName and User_Password=@User_Password";
            return DapperQuery<Users>.DoQueryT(sql,us);
        }
        /// <summary>
        /// 根据条件获取用户
        /// </summary>
        /// <param name="sqlWhere"></param>
        /// <returns></returns>
        public static List<Users> GetUserList(string sqlWhere)
        {
            var sql = "select * from Users where 1=1 ";
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sql += sqlWhere;
            }
            List<Users> lst = DapperQuery<Users>.DoQueryList(sql, null);
            return lst;
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="us"></param>
        /// <returns></returns>
        public static BaseAnswer UpdateUsersPassWord(Users us)
        {
            var sq1 = "update Users set User_Password=@User_Password where User_Id=@User_Id";
            BaseAnswer bar = DapperEdit<Users>.DoEdit(sq1, us);
            return bar;
        }

    }
}
